package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.RequireListCallback;
import cn.hrlly.tao2shou.domain.RequireList;
import cn.hrlly.tao2shou.listener.OnRequireListListener;
import cn.hrlly.tao2shou.utils.CacheUtil;

/**
 * User: gengliang
 * Date: 2016-01-29
 * Time: 20:27
 */

public class RequireListBizImpl implements RequireListBiz {

    private OnRequireListListener onRequireListListener;
    private CacheUtil cacheUtil;

    public RequireListBizImpl(OnRequireListListener onRequireListListener,Context context){
        this.onRequireListListener=onRequireListListener;
        this.cacheUtil=new CacheUtil(context);
    }

    @Override
    public void showRequireList(RequireList requireList) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_require_list)
                .addParams(Config.key_page, String.valueOf(requireList.getPage()))
                .addParams(Config.key_page_count, String.valueOf(requireList.getPageCount()))
                .addParams(Config.key_classification,requireList.getClassification())
                .build()
                .execute(new RequireListCallback(onRequireListListener));
    }

    @Override
    public void saveCacheRequireList(RequireList requireList) {
        cacheUtil.putRequireList(requireList);
    }

    @Override
    public RequireList getCacheRequireList() {
        RequireList requireList=cacheUtil.getRequireList();
        return requireList;
    }
}
